package com.momo.two;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.UUID;

/**
 * @author Kagome
 * @title: MyServerHandler
 * @projectName boot2.X-netty
 * @description: TODO
 * @date 2019/6/1 9:47
 */
public class MyServerHandler extends SimpleChannelInboundHandler<String> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
        Channel channel = ctx.channel();
        System.out.println("客户端地址" + channel.remoteAddress() + "收到客户端消息:" + msg);
        channel.writeAndFlush("from server:"+ UUID.randomUUID());

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.getCause();
        ctx.close();
    }
}
